# encoding=utf-8
from flask import Flask, json, request
from flask_cors import *
import logging

def create_app(import_name):
    app = Flask(import_name)
    # 日志配置
    logging.basicConfig(level=logging.DEBUG)
    handler = logging.FileHandler(filename='./weatherapp.log', encoding='utf-8')
    logging_format = logging.Formatter(
        '%(asctime)s - %(levelname)s - %(filename)s - %(funcName)s - %(lineno)s - %(message)s')
    handler.setFormatter(logging_format)
    app.logger.addHandler(handler)
    return app

# 创建app应用,__name__是python预定义变量，被设置为使用本模块
weatherapp = create_app(__name__)
# 解决Flask返回的汉字为unicode编码
weatherapp.config['JSON_AS_ASCII'] = False
CORS(weatherapp, supports_credentials=True, resources=r"/*")